/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package IFSv2.Forms;

import IFSv2.Connection.DBConnection;
import IFSv2.Forms.Utilities.frmFind;
import IFSv2.Util.utilAutoCompletion;
import IFSv2.Models.mdlCurrency;
import IFSv2.Util.utilData;
import IFSv2.Util.utilSystemPath;
import java.awt.AWTKeyStroke;
import java.awt.Component;
import java.awt.Container;
import java.awt.KeyboardFocusManager;
import java.awt.event.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;

/**
 *
 * @author Joel
 */
public class frmAPdtl extends javax.swing.JFrame {

    private final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#,###,###,##0.00");
    
    private String m_strType;

    private ArrayList<ArrayList<String>> list = new ArrayList();
    private ArrayList<Float> vatList = new ArrayList<>();
    private ArrayList<Float> wtaxList = new ArrayList<>();
    private ArrayList<String> taxIDList = new ArrayList<>();
    
    private int index=0;
    private float vat=0, wtax=0;
    private double taxableAmt=0, vatAmt=0, wtaxAmt=0, tranAmt=0;
    
    private Map<String, ArrayList<String>> mapValue;
        
    public frmAPdtl(String currOperation) {
     
        m_strType = "NEW";
        setIconImage(utilSystemPath.getFormImage(this.getClass().getResource("/IFSv2/Images/timlogo.png")));
        initComponents();
      
        enableTraversal();
        
        try {
            fillComponents();
        } catch (SQLException ex) {
            Logger.getLogger(frmAPdtl.class.getName()).log(Level.SEVERE, null, ex);
        }
        setWindowLocation();
        loadButtons();
        if("EDIT".equals(currOperation) || "ADD".equals(currOperation)){
            instantiateMap();
            startListening(dtlPanel);
        }else{
            enableAllFields(false);
        }
    }
    
    public frmAPdtl(HashMap rowMap, String currOperation){
        
        m_strType = "EDIT";
        setIconImage(utilSystemPath.getFormImage(this.getClass().getResource("/IFSv2/Images/timlogo.png")));
        initComponents();
        
        enableTraversal();
        
        try {
            fillComponents();
        } catch (SQLException ex) {
            Logger.getLogger(frmAPdtl.class.getName()).log(Level.SEVERE, null, ex);
        }
        displayData(rowMap);
        setWindowLocation();
        loadButtons();
        if("EDIT".equals(currOperation) || "ADD".equals(currOperation)){
            instantiateMap();
            startListening(dtlPanel);
        }else{
            enableAllFields(false);
        }
    }

    private void enableTraversal(){
    
        Container root = this;
        Set<AWTKeyStroke> defaultKeys = root.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
        Set<AWTKeyStroke> newKeys = new HashSet<>(defaultKeys);
        newKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0));
        root.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, newKeys);
    }
    
    private void loadButtons(){
        btnNew.setVisible(false);
        btnSave.setVisible(false);
        btnSave.setEnabled(true);
    }
    
    private void startListening(javax.swing.JPanel thisPanel){
    
        for(Component cmp: thisPanel.getComponents()){
        
            if(cmp instanceof javax.swing.JPanel){
                startListening((javax.swing.JPanel)cmp);
            }
            if(cmp instanceof javax.swing.JComboBox){
            
                javax.swing.JComboBox cmdField = (javax.swing.JComboBox) cmp;
                
                cmdField.addItemListener(new java.awt.event.ItemListener() {

                    @Override
                    public void itemStateChanged(ItemEvent e) {
                        reloadButtons();
                    }
                });  
            }
            if(cmp instanceof javax.swing.JTextField){
            
                javax.swing.JTextField txtField = (javax.swing.JTextField) cmp;
                
                txtField.addKeyListener(new java.awt.event.KeyAdapter() {
                    
                    @Override
                    public void keyPressed(final java.awt.event.KeyEvent evt){
                        reloadButtons();   
                    }       
                });
            }
        }
        
    }
    
    private void reloadButtons(){
        switch (m_strType) {
            case "NEW":
                btnSave.setVisible(true);
                btnNew.setVisible(true);
                break;
            case "EDIT":
                btnSave.setVisible(true);
                break;
        }
        
    
    }
    
    private void fillComponents() throws SQLException{
        
        ResultSet rsAccount;

        String strAccount = "SELECT AccountDesc FROM Account WHERE Active = 1 ORDER BY Account";
        
        rsAccount = DBConnection.getActiveConnection().createStatement().executeQuery(strAccount);
        
        while(rsAccount.next()){
            cbAccount.addItem(rsAccount.getString("AccountDesc"));
        }
        cbAccount.setSelectedIndex(-1);        
        utilAutoCompletion.enable(cbAccount);

        rsAccount.close();
        
        ResultSet rsSubaccount;

        String strSubaccount = "SELECT SubDesc FROM subaccount WHERE Active = 1 ORDER BY SubDesc";
        
        rsSubaccount = DBConnection.getActiveConnection().createStatement().executeQuery(strSubaccount);
        
        while(rsSubaccount.next()){
            cbSubAccount.addItem(rsSubaccount.getString("SubDesc"));
        }
        cbSubAccount.setSelectedIndex(-1);        
        utilAutoCompletion.enable(cbSubAccount);

        rsSubaccount.close();
        
        ResultSet rsAPTaxID;
        
        String strAPTaxID = "SELECT TaxID, VAT, WTAX FROM aptaxid ORDER BY TaxID";
        
        rsAPTaxID = DBConnection.getActiveConnection().createStatement().executeQuery(strAPTaxID);
        
        while(rsAPTaxID.next()){
            String taxID = rsAPTaxID.getString("TaxID");
            cbTaxID.addItem(taxID);
            taxIDList.add(taxID);
            vatList.add(rsAPTaxID.getFloat("VAT"));
            wtaxList.add(rsAPTaxID.getFloat("WTAX"));
            
        }
        cbTaxID.setSelectedIndex(0);
        utilAutoCompletion.enable(cbTaxID);
        
        rsAPTaxID.close();
    }
    
    
    
    private void getTaxValues(String taxID){
    
        int index = taxIDList.indexOf(taxID);
        if(index!=-1){
            vat = vatList.get(index);
            wtax = wtaxList.get(index);
        }else{
            vat = 0;
            wtax = 0;
        }
    }
    
    private void checkQtyUnit(){
        if(!(txtQty.getText().isEmpty()) && !(txtUnitCost.getText().isEmpty()) && cbTaxID.getSelectedIndex() != -1){
            computeTranAmt();
        }
    }
    
    //Given details, solve for tranAmt
    private void computeTranAmt(){
        //convert formatted string to plain string for typecasting
        String qty = txtQty.getText().replace(",","").replace("(","").replace(")","");
        String uCost = txtUnitCost.getText().replace(",","").replace("(","").replace(")","");
        
        //taxableAmout = Qty * UnitCost
        taxableAmt = Double.parseDouble(qty) * Double.parseDouble(uCost);
        taxableAmt = (double)(Math.round(taxableAmt*100))/100; //round-off 2 decimal places
        //VatAmt = taxableAmount * Vat/100
        vatAmt = taxableAmt * (vat/100);
        vatAmt = (double)(Math.round(vatAmt*100))/100;
        //WTaxAmt = taxableAmount * wtax/100
        wtaxAmt = taxableAmt * (wtax/100);
        wtaxAmt = (double)(Math.round(wtaxAmt*100))/100;
        //TranAmt = taxableAmount + VatAmt
        tranAmt = taxableAmt + vatAmt;
        tranAmt = (double)(Math.round(tranAmt*100))/100;
        txtTranAmt.setText(String.valueOf(DECIMAL_FORMAT.format(tranAmt)));
        writeValues();
    }
    
    //Given the tranAmt, solve for details
    private void computeDetails(){
        String trnAmt = txtTranAmt.getText().replace(",","").replace("(","").replace(")","");
        
        tranAmt = Double.parseDouble(trnAmt);
        //
        taxableAmt = tranAmt / ( 1 + (vat/100));
        taxableAmt = (double)(Math.round(taxableAmt*100))/100;
        //
        vatAmt = tranAmt - taxableAmt;
        vatAmt = (double)(Math.round(vatAmt*100))/100;
        //
        wtaxAmt = taxableAmt * (wtax/100);
        wtaxAmt = (double)(Math.round(wtaxAmt*100))/100;
        //
        txtQty.setText("1.00");
        txtUnitCost.setText(String.valueOf(DECIMAL_FORMAT.format(taxableAmt)));
        writeValues();
    }
    
    private String getBaseRate(String currRate){
        currRate = currRate.replace(",","").replace("(","").replace(")","");
        double rate = Double.parseDouble(currRate) / mdlCurrency.exchangeRate;
        rate = (double)(Math.round(rate*100))/100;
        return String.valueOf(rate);
    }
    
    private void writeValues(){
    
        txtTaxable.setText(String.valueOf(DECIMAL_FORMAT.format(taxableAmt)));
        txtVAT.setText(String.valueOf(DECIMAL_FORMAT.format(vatAmt)));
        txtWTax.setText(String.valueOf(DECIMAL_FORMAT.format(wtaxAmt)));
        
    }
    
    private void setWindowLocation(){
        this.setLocationRelativeTo(null);
    }
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        dtlPanel = new javax.swing.JPanel();
        btnClose = new javax.swing.JButton();
        btnNew = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        btnSave = new javax.swing.JButton();
        pnlInfo = new javax.swing.JPanel();
        lblAccount = new javax.swing.JLabel();
        cbAccount = new javax.swing.JComboBox();
        cmdAccount = new javax.swing.JButton();
        lblSubAccount = new javax.swing.JLabel();
        cbSubAccount = new javax.swing.JComboBox();
        cmdSubaccount = new javax.swing.JButton();
        lblPostRef = new javax.swing.JLabel();
        txtPostRef = new javax.swing.JTextField();
        lblTaxID = new javax.swing.JLabel();
        lblQty = new javax.swing.JLabel();
        lblUnitCost = new javax.swing.JLabel();
        txtQty = new javax.swing.JFormattedTextField();
        txtUnitCost = new javax.swing.JFormattedTextField();
        txtTranAmt = new javax.swing.JFormattedTextField();
        lblTranAmt = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        txtInterCo = new javax.swing.JTextField();
        cbTaxID = new javax.swing.JComboBox();
        cmdTaxID = new javax.swing.JButton();
        lblTaxable = new javax.swing.JLabel();
        txtTaxable = new javax.swing.JFormattedTextField();
        lblVAT = new javax.swing.JLabel();
        lblWTax = new javax.swing.JLabel();
        txtVAT = new javax.swing.JFormattedTextField();
        txtWTax = new javax.swing.JFormattedTextField();
        txtSubAccount = new javax.swing.JTextField();
        txtAccount = new javax.swing.JTextField();
        panelGroupSegments = new javax.swing.JPanel();
        lblSubLedger = new javax.swing.JLabel();
        lblProjID = new javax.swing.JLabel();
        lblBudgetID = new javax.swing.JLabel();
        lblJONo = new javax.swing.JLabel();
        lblLCID = new javax.swing.JLabel();
        cbSubLedger = new javax.swing.JComboBox();
        cbBudgetID = new javax.swing.JComboBox();
        cbJONo = new javax.swing.JComboBox();
        cbProjID = new javax.swing.JComboBox();
        cbLCID = new javax.swing.JComboBox();
        cmdSubLedger = new javax.swing.JButton();
        cmdProjID = new javax.swing.JButton();
        cmdLCID = new javax.swing.JButton();
        cmdJONo = new javax.swing.JButton();
        cmdBudgetID = new javax.swing.JButton();
        pnlDetail = new javax.swing.JPanel();
        lblParticulars = new javax.swing.JLabel();
        txtParticulars = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setModalExclusionType(java.awt.Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
        setResizable(false);

        dtlPanel.setBackground(new java.awt.Color(255, 255, 255));

        btnClose.setText("Close");
        btnClose.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnCloseMouseClicked(evt);
            }
        });

        btnNew.setText("Save & New");
        btnNew.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnNewMouseClicked(evt);
            }
        });
        btnNew.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                btnNewKeyPressed(evt);
            }
        });

        btnSave.setText("Save");
        btnSave.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnSaveMouseClicked(evt);
            }
        });

        pnlInfo.setBackground(new java.awt.Color(255, 255, 255));
        pnlInfo.setBorder(javax.swing.BorderFactory.createTitledBorder("Info"));

        lblAccount.setText("Account");

        cbAccount.setEditable(true);
        cbAccount.setName("AccountDescription");
        cbAccount.setNextFocusableComponent(cbSubAccount);

        cmdAccount.setText("...");
        cmdAccount.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cmdAccountMouseClicked(evt);
            }
        });

        lblSubAccount.setText("SubAccount");

        cbSubAccount.setEditable(true);
        cbSubAccount.setName("SubDescription");
        cbSubAccount.setNextFocusableComponent(cbTaxID);

        cmdSubaccount.setText("...");
        cmdSubaccount.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cmdSubaccountMouseClicked(evt);
            }
        });

        lblPostRef.setText("PostRef");

        txtPostRef.setName("PostRef");
        txtPostRef.setNextFocusableComponent(txtParticulars);

        lblTaxID.setText("TaxID");

        lblQty.setText("Qty");

        lblUnitCost.setText("UnitCost");

        txtQty.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,###.00"))));
        txtQty.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtQty.setText("1.0");
        txtQty.setName("Qty");
        txtQty.setNextFocusableComponent(txtUnitCost);
        txtQty.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtQtyFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtQtyFocusLost(evt);
            }
        });
        txtQty.setNextFocusableComponent(txtUnitCost);

        txtUnitCost.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,##0.00;(#,##0.00)"))));
        txtUnitCost.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtUnitCost.setText("0.00");
        txtUnitCost.setName("CurUnitCost");
        txtUnitCost.setNextFocusableComponent(txtTaxable);
        txtUnitCost.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtUnitCostFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtUnitCostFocusLost(evt);
            }
        });
        txtUnitCost.setNextFocusableComponent(txtTaxable);

        txtTranAmt.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,##0.00;(#,##0.00)"))));
        txtTranAmt.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtTranAmt.setText("0.00");
        txtTranAmt.setToolTipText("");
        txtTranAmt.setName("CurTranAmt");
        txtTranAmt.setNextFocusableComponent(txtInterCo);
        txtTranAmt.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtTranAmtFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtTranAmtFocusLost(evt);
            }
        });

        lblTranAmt.setText("TranAmt");

        jLabel1.setText("InterCo");

        txtInterCo.setName("InterCo");
        txtInterCo.setNextFocusableComponent(txtPostRef);

        cbTaxID.setEditable(true);
        cbTaxID.setName("TaxID");
        cbTaxID.setNextFocusableComponent(txtQty);
        cbTaxID.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbTaxIDActionPerformed(evt);
            }
        });

        cmdTaxID.setText("...");
        cmdTaxID.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cmdTaxIDMouseClicked(evt);
            }
        });

        lblTaxable.setText("Taxable");

        txtTaxable.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,##0.00;(#,##0.00)"))));
        txtTaxable.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtTaxable.setText("0.00");
        txtTaxable.setName("CurTaxable");
        txtTaxable.setNextFocusableComponent(txtVAT);
        txtTaxable.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtTaxableFocusGained(evt);
            }
        });

        lblVAT.setText("VAT");

        lblWTax.setText("WTax");

        txtVAT.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,##0.00;(#,##0.00)"))));
        txtVAT.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtVAT.setText("0.00");
        txtVAT.setName("CurVAT");
        txtVAT.setNextFocusableComponent(txtWTax);
        txtVAT.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtVATFocusGained(evt);
            }
        });

        txtWTax.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,##0.00;(#,##0.00)"))));
        txtWTax.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtWTax.setText("0.00");
        txtWTax.setName("CurWTax");
        txtWTax.setNextFocusableComponent(txtTranAmt);
        txtWTax.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtWTaxFocusGained(evt);
            }
        });

        txtSubAccount.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtSubAccountFocusLost(evt);
            }
        });

        txtAccount.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtAccountFocusLost(evt);
            }
        });

        javax.swing.GroupLayout pnlInfoLayout = new javax.swing.GroupLayout(pnlInfo);
        pnlInfo.setLayout(pnlInfoLayout);
        pnlInfoLayout.setHorizontalGroup(
            pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlInfoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlInfoLayout.createSequentialGroup()
                        .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblTaxID)
                            .addComponent(lblQty))
                        .addGap(38, 38, 38)
                        .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cbTaxID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtQty, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cmdTaxID)
                            .addGroup(pnlInfoLayout.createSequentialGroup()
                                .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(pnlInfoLayout.createSequentialGroup()
                                        .addGap(1, 1, 1)
                                        .addComponent(jLabel1))
                                    .addComponent(lblPostRef))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtInterCo, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)
                                    .addComponent(txtPostRef)))))
                    .addGroup(pnlInfoLayout.createSequentialGroup()
                        .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblSubAccount)
                            .addComponent(lblAccount)
                            .addComponent(lblUnitCost)
                            .addComponent(lblTaxable)
                            .addComponent(lblVAT)
                            .addComponent(lblWTax)
                            .addComponent(lblTranAmt))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlInfoLayout.createSequentialGroup()
                                .addComponent(txtAccount)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cbAccount, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cmdAccount))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlInfoLayout.createSequentialGroup()
                                .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(pnlInfoLayout.createSequentialGroup()
                                        .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(txtUnitCost, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 96, Short.MAX_VALUE)
                                            .addComponent(txtTaxable, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(txtVAT, javax.swing.GroupLayout.Alignment.LEADING))
                                        .addGap(0, 0, Short.MAX_VALUE))
                                    .addGroup(pnlInfoLayout.createSequentialGroup()
                                        .addComponent(txtSubAccount)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(cbSubAccount, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cmdSubaccount))
                            .addGroup(pnlInfoLayout.createSequentialGroup()
                                .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtWTax, javax.swing.GroupLayout.DEFAULT_SIZE, 96, Short.MAX_VALUE)
                                    .addComponent(txtTranAmt))
                                .addGap(0, 0, Short.MAX_VALUE)))))
                .addContainerGap())
        );
        pnlInfoLayout.setVerticalGroup(
            pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlInfoLayout.createSequentialGroup()
                .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbAccount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblAccount)
                    .addComponent(cmdAccount)
                    .addComponent(txtAccount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblSubAccount)
                    .addComponent(cbSubAccount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmdSubaccount)
                    .addComponent(txtSubAccount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblTaxID)
                    .addComponent(cbTaxID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmdTaxID))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlInfoLayout.createSequentialGroup()
                        .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtQty, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblQty))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtUnitCost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblUnitCost))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtTaxable, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblTaxable))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblVAT)
                            .addComponent(txtVAT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblWTax)
                            .addComponent(txtWTax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblTranAmt)
                            .addComponent(txtTranAmt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(pnlInfoLayout.createSequentialGroup()
                        .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(txtInterCo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblPostRef)
                            .addComponent(txtPostRef, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panelGroupSegments.setBackground(new java.awt.Color(255, 255, 255));
        panelGroupSegments.setBorder(javax.swing.BorderFactory.createTitledBorder("Group Segments"));

        lblSubLedger.setText("SubLedger");

        lblProjID.setText("ProjID");

        lblBudgetID.setText("BudgetID");

        lblJONo.setText("JONo");

        lblLCID.setText("LCID");

        cbSubLedger.setEditable(true);
        cbSubLedger.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbSubLedger.setName("SubLedger");
        cbSubLedger.setNextFocusableComponent(cbProjID);

        cbBudgetID.setEditable(true);
        cbBudgetID.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbBudgetID.setName("BudgetID");
        cbBudgetID.setNextFocusableComponent(cbJONo);

        cbJONo.setEditable(true);
        cbJONo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbJONo.setName("JONo");
        cbJONo.setNextFocusableComponent(cmdLCID);

        cbProjID.setEditable(true);
        cbProjID.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbProjID.setName("ProjID");
        cbProjID.setNextFocusableComponent(cbBudgetID);

        cbLCID.setEditable(true);
        cbLCID.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbLCID.setName("LCID");
        cbLCID.setNextFocusableComponent(btnNew);

        cmdSubLedger.setText("...");
        cmdSubLedger.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cmdSubLedgerMouseClicked(evt);
            }
        });

        cmdProjID.setText("...");
        cmdProjID.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cmdProjIDMouseClicked(evt);
            }
        });

        cmdLCID.setText("...");
        cmdLCID.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cmdLCIDMouseClicked(evt);
            }
        });

        cmdJONo.setText("...");
        cmdJONo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cmdJONoMouseClicked(evt);
            }
        });

        cmdBudgetID.setText("...");
        cmdBudgetID.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cmdBudgetIDMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout panelGroupSegmentsLayout = new javax.swing.GroupLayout(panelGroupSegments);
        panelGroupSegments.setLayout(panelGroupSegmentsLayout);
        panelGroupSegmentsLayout.setHorizontalGroup(
            panelGroupSegmentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelGroupSegmentsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelGroupSegmentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblBudgetID)
                    .addComponent(lblJONo)
                    .addComponent(lblProjID)
                    .addComponent(lblSubLedger)
                    .addComponent(lblLCID))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelGroupSegmentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(cbProjID, javax.swing.GroupLayout.Alignment.LEADING, 0, 251, Short.MAX_VALUE)
                    .addComponent(cbBudgetID, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cbJONo, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cbLCID, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cbSubLedger, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelGroupSegmentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cmdSubLedger)
                    .addComponent(cmdProjID)
                    .addComponent(cmdLCID)
                    .addComponent(cmdJONo)
                    .addComponent(cmdBudgetID))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        panelGroupSegmentsLayout.setVerticalGroup(
            panelGroupSegmentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelGroupSegmentsLayout.createSequentialGroup()
                .addGap(2, 2, 2)
                .addGroup(panelGroupSegmentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblSubLedger)
                    .addComponent(cbSubLedger, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmdSubLedger))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelGroupSegmentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblProjID)
                    .addComponent(cbProjID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmdProjID))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelGroupSegmentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblBudgetID)
                    .addComponent(cbBudgetID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmdBudgetID))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelGroupSegmentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblJONo)
                    .addComponent(cbJONo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmdJONo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelGroupSegmentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblLCID)
                    .addComponent(cbLCID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmdLCID))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pnlDetail.setBackground(new java.awt.Color(255, 255, 255));
        pnlDetail.setBorder(javax.swing.BorderFactory.createTitledBorder("Detail"));

        lblParticulars.setText("Particulars");

        txtParticulars.setName("Particulars");
        txtParticulars.setNextFocusableComponent(cbSubLedger);

        javax.swing.GroupLayout pnlDetailLayout = new javax.swing.GroupLayout(pnlDetail);
        pnlDetail.setLayout(pnlDetailLayout);
        pnlDetailLayout.setHorizontalGroup(
            pnlDetailLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDetailLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblParticulars)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtParticulars)
                .addContainerGap())
        );
        pnlDetailLayout.setVerticalGroup(
            pnlDetailLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDetailLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlDetailLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblParticulars)
                    .addComponent(txtParticulars, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout dtlPanelLayout = new javax.swing.GroupLayout(dtlPanel);
        dtlPanel.setLayout(dtlPanelLayout);
        dtlPanelLayout.setHorizontalGroup(
            dtlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(dtlPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(dtlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panelGroupSegments, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pnlDetail, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pnlInfo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(dtlPanelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 230, Short.MAX_VALUE)
                        .addGroup(dtlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(dtlPanelLayout.createSequentialGroup()
                                .addComponent(btnNew)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnSave)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnClose))
                            .addComponent(jSeparator1))
                        .addGap(14, 14, 14)))
                .addContainerGap())
        );
        dtlPanelLayout.setVerticalGroup(
            dtlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(dtlPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnlInfo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlDetail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(4, 4, 4)
                .addComponent(panelGroupSegments, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(dtlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnClose)
                    .addComponent(btnSave)
                    .addComponent(btnNew))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(dtlPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(dtlPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnNewMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnNewMouseClicked
        addToListNew(true);
    }//GEN-LAST:event_btnNewMouseClicked

    private void btnCloseMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCloseMouseClicked
        this.dispose();
    }//GEN-LAST:event_btnCloseMouseClicked

    private void btnNewKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_btnNewKeyPressed
        if(evt.getKeyCode() == KeyEvent.VK_ENTER || evt.getKeyCode() == KeyEvent.VK_SPACE){
            addToListNew(true);
        }
    }//GEN-LAST:event_btnNewKeyPressed

    private void cmdAccountMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cmdAccountMouseClicked
        if (cmdAccount.isEnabled())
            SearchAccount();
    }//GEN-LAST:event_cmdAccountMouseClicked

    private void cmdSubaccountMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cmdSubaccountMouseClicked
        if (cmdSubaccount.isEnabled())
            SearchSubaccount();
    }//GEN-LAST:event_cmdSubaccountMouseClicked

    private void btnSaveMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnSaveMouseClicked
        addToListNew(false);
    }//GEN-LAST:event_btnSaveMouseClicked

    private void cmdSubLedgerMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cmdSubLedgerMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_cmdSubLedgerMouseClicked

    private void cmdProjIDMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cmdProjIDMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_cmdProjIDMouseClicked

    private void cmdLCIDMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cmdLCIDMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_cmdLCIDMouseClicked

    private void cmdJONoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cmdJONoMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_cmdJONoMouseClicked

    private void cmdBudgetIDMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cmdBudgetIDMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_cmdBudgetIDMouseClicked

    private void cmdTaxIDMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cmdTaxIDMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_cmdTaxIDMouseClicked

    private void cbTaxIDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbTaxIDActionPerformed
        getTaxValues(cbTaxID.getSelectedItem().toString());
        if(!(txtTranAmt.getText().isEmpty()) || (!(txtQty.getText().isEmpty()) && !(txtUnitCost.getText().isEmpty()))){
            computeTranAmt();
        }
    }//GEN-LAST:event_cbTaxIDActionPerformed

    private void txtQtyFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtQtyFocusLost
        checkQtyUnit();
    }//GEN-LAST:event_txtQtyFocusLost

    private void txtUnitCostFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtUnitCostFocusLost
        checkQtyUnit();
    }//GEN-LAST:event_txtUnitCostFocusLost

    private void txtTranAmtFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtTranAmtFocusLost
        if(!(txtTranAmt.getText().isEmpty())){
            computeDetails();
        }
    }//GEN-LAST:event_txtTranAmtFocusLost

    private void txtQtyFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtQtyFocusGained
        highlightField(txtQty);
    }//GEN-LAST:event_txtQtyFocusGained

    private void txtUnitCostFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtUnitCostFocusGained
        highlightField(txtUnitCost);
    }//GEN-LAST:event_txtUnitCostFocusGained

    private void txtTaxableFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtTaxableFocusGained
        highlightField(txtTaxable);
    }//GEN-LAST:event_txtTaxableFocusGained

    private void txtVATFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtVATFocusGained
        highlightField(txtVAT);
    }//GEN-LAST:event_txtVATFocusGained

    private void txtWTaxFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtWTaxFocusGained
        highlightField(txtWTax);
    }//GEN-LAST:event_txtWTaxFocusGained

    private void txtTranAmtFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtTranAmtFocusGained
        highlightField(txtTranAmt);
    }//GEN-LAST:event_txtTranAmtFocusGained

    private void txtAccountFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtAccountFocusLost
        cbAccount.setSelectedItem(utilData.getDescription("account", "Account", "AccountDesc", txtAccount.getText()));
    }//GEN-LAST:event_txtAccountFocusLost

    private void txtSubAccountFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtSubAccountFocusLost
        cbSubAccount.setSelectedItem(utilData.getDescription("subaccount", "SubAcct", "SubDesc", txtSubAccount.getText()));
    }//GEN-LAST:event_txtSubAccountFocusLost

    private void highlightField(final JTextField textField){
        SwingUtilities.invokeLater( new Runnable() {
            @Override
            public void run() {
                textField.selectAll();              
            }
        });
    }
    
    private void SearchAccount(){
    
        final frmFind fFindGrid;
        String strText = ((javax.swing.JTextField) cbAccount.getEditor().getEditorComponent()).getText();
        
        if(strText.isEmpty())
            fFindGrid = new frmFind(null, false, "Account","AccountDesc", "Account");
        else 
            fFindGrid = new frmFind(null, false, "Account","AccountDesc",cbAccount.getSelectedItem().toString(), "Account");
        
        fFindGrid.setVisible(true);
        fFindGrid.addWindowListener(new WindowListener(){
            //<editor-fold defaultstate="collapsed" desc="abstract methods">
            @Override
            public void windowOpened(WindowEvent e) {}

            @Override
            public void windowClosing(WindowEvent e) {}

            @Override
            public void windowClosed(WindowEvent e) {
                if(!"".equals(fFindGrid.getSelectedID()))
                 cbAccount.setSelectedItem(fFindGrid.getSelectedID());
            }
            
            @Override
            public void windowIconified(WindowEvent e) {}

            @Override
            public void windowDeiconified(WindowEvent e) {}

            @Override
            public void windowActivated(WindowEvent e) {}

            @Override
            public void windowDeactivated(WindowEvent e) {}
            //</editor-fold>
        });
        
    }
    
    private void SearchSubaccount(){
    
        final frmFind fFindGrid;
        String strText = ((javax.swing.JTextField) cbSubAccount.getEditor().getEditorComponent()).getText();
        
        if(strText.isEmpty())
            fFindGrid = new frmFind(null, false, "SubAccount","SubDesc", "SubAccount");
        else 
            fFindGrid = new frmFind(null, false, "SubAccount","SubDesc",cbSubAccount.getSelectedItem().toString(), "SubAcct");
        
        fFindGrid.setVisible(true);
        fFindGrid.addWindowListener(new WindowListener(){
            //<editor-fold defaultstate="collapsed" desc="abstract methods">
            @Override
            public void windowOpened(WindowEvent e) {}

            @Override
            public void windowClosing(WindowEvent e) {}

            @Override
            public void windowClosed(WindowEvent e) {
                if(!"".equals(fFindGrid.getSelectedID()))
                 cbSubAccount.setSelectedItem(fFindGrid.getSelectedID());
            }
            
            @Override
            public void windowIconified(WindowEvent e) {}

            @Override
            public void windowDeiconified(WindowEvent e) {}

            @Override
            public void windowActivated(WindowEvent e) {}

            @Override
            public void windowDeactivated(WindowEvent e) {}
            //</editor-fold>
        });
        
    }

    
    private void instantiateMap(){
    
        /*
         * Put all the name of each field to the map. The name of the field must 
         * be of the same name with the table name to map the data. Account
         * Description and SubDescription is also added to fill the info on the
         * grid. No is added for tracking purposes.
         */
        mapValue = new HashMap();
        mapValue.put("No", new ArrayList<String>());
        mapValue.put(cbAccount.getName(), new ArrayList<String>());
        mapValue.put("Account", new ArrayList<String>());
        mapValue.put(cbSubAccount.getName(), new ArrayList<String>());
        mapValue.put("SubAccount", new ArrayList<String>());
        mapValue.put(txtPostRef.getName(), new ArrayList<String>());
        mapValue.put(txtInterCo.getName(), new ArrayList<String>());
        mapValue.put(cbTaxID.getName(), new ArrayList<String>());
        mapValue.put(txtQty.getName(), new ArrayList<String>());
        mapValue.put(txtUnitCost.getName(), new ArrayList<String>());
        mapValue.put("UnitCost", new ArrayList<String>());
        mapValue.put(txtTaxable.getName(), new ArrayList<String>());
        mapValue.put("Taxable", new ArrayList<String>());
        mapValue.put(txtVAT.getName(), new ArrayList<String>());
        mapValue.put("VAT", new ArrayList<String>());
        mapValue.put(txtWTax.getName(), new ArrayList<String>());
        mapValue.put("WTax", new ArrayList<String>());
        mapValue.put(txtTranAmt.getName(), new ArrayList<String>());
        mapValue.put("TranAmt", new ArrayList<String>());
        mapValue.put(txtParticulars.getName(), new ArrayList<String>());
        mapValue.put(cbSubLedger.getName(), new ArrayList<String>());
        mapValue.put(cbProjID.getName(), new ArrayList<String>());
        mapValue.put(cbBudgetID.getName(), new ArrayList<String>());
        mapValue.put(cbJONo.getName(), new ArrayList<String>());
        mapValue.put(cbLCID.getName(), new ArrayList<String>());
        
    }
    

    private void addToListNew(boolean type){
    
        mapValue.get("No").add(String.valueOf(++index));
        mapValue.get("Account").add(utilData.getID("account", "Account", "AccountDesc", cbAccount.getSelectedItem()));
        mapValue.get(cbAccount.getName()).add(cbAccount.getSelectedItem().toString());
        mapValue.get("SubAccount").add(utilData.getID("subaccount", "SubAcct", "SubDesc", cbSubAccount.getSelectedItem()));
        mapValue.get(cbSubAccount.getName()).add(cbSubAccount.getSelectedItem().toString());
        mapValue.get(txtPostRef.getName()).add(txtPostRef.getText());
        mapValue.get(cbTaxID.getName()).add(cbTaxID.getSelectedItem().toString());
        mapValue.get(txtQty.getName()).add(txtQty.getText());
        mapValue.get(txtUnitCost.getName()).add(txtUnitCost.getText());
        mapValue.get("UnitCost").add(getBaseRate(txtUnitCost.getText()));
        mapValue.get(txtTaxable.getName()).add(txtTaxable.getText());
        mapValue.get("Taxable").add(getBaseRate(txtTaxable.getText()));
        mapValue.get(txtVAT.getName()).add(txtVAT.getText());
        mapValue.get("VAT").add(getBaseRate(txtVAT.getText()));
        mapValue.get(txtWTax.getName()).add(txtWTax.getText());
        mapValue.get("WTax").add(getBaseRate(txtWTax.getText()));
        mapValue.get(txtTranAmt.getName()).add(txtTranAmt.getText());
        mapValue.get("TranAmt").add(txtTranAmt.getText());
        mapValue.get(txtInterCo.getName()).add(txtInterCo.getText());
        mapValue.get(txtParticulars.getName()).add(txtParticulars.getText());
        mapValue.get(cbSubLedger.getName()).add(cbSubLedger.getSelectedItem().toString());
        mapValue.get(cbProjID.getName()).add(cbProjID.getSelectedItem().toString());
        mapValue.get(cbBudgetID.getName()).add(cbBudgetID.getSelectedItem().toString());
        mapValue.get(cbJONo.getName()).add(cbJONo.getSelectedItem().toString());
        mapValue.get(cbLCID.getName()).add(cbLCID.getSelectedItem().toString());
        
        
        if(type){
            clearAllFields(dtlPanel);
            loadButtons();
        }else{
            btnSave.setEnabled(false);
            btnNew.setEnabled(false);
        }
    }
    
    public ArrayList getDtlList(){
        
        if("NEW".equals(m_strType)){
            return list;
        }
        else{
            if(!list.isEmpty()){
                return list.get(0);
            }
            return null;
        }
    }
    
    public Map getDtlMap(){
    
        return mapValue;
    
    }
        
    private void displayData(HashMap rowMap){
        for(int i=0; i< dtlPanel.getComponentCount() ; i++){
            
            if(dtlPanel.getComponent(i) instanceof javax.swing.JPanel){
                javax.swing.JPanel thisPanel = (javax.swing.JPanel)dtlPanel.getComponent(i);
                for(int j=0; j< thisPanel.getComponentCount() ; j++){
                    if(thisPanel.getComponent(j) instanceof javax.swing.JPanel){
                    } else if (thisPanel.getComponent(j) instanceof javax.swing.JTextField) {
                        javax.swing.JTextField txtField = (javax.swing.JTextField) thisPanel.getComponent(j);
                        if(rowMap.get(txtField.getName()) != null){
                            txtField.setText(rowMap.get(txtField.getName()).toString());
                        }
                    }else if (thisPanel.getComponent(j) instanceof javax.swing.JComboBox) {
                        javax.swing.JComboBox cbField = (javax.swing.JComboBox) thisPanel.getComponent(j);
                        if(rowMap.get(cbField.getName()) != null    ){
                            cbField.setSelectedItem(rowMap.get(cbField.getName()));
                        }
                    }
                }
            } else if (dtlPanel.getComponent(i) instanceof javax.swing.JTextField) {
                javax.swing.JTextField txtField = (javax.swing.JTextField) dtlPanel.getComponent(i);
                txtField.setText(rowMap.get(txtField.getName()).toString());
            }else if (dtlPanel.getComponent(i) instanceof javax.swing.JComboBox) {
                javax.swing.JComboBox cbField = (javax.swing.JComboBox) dtlPanel.getComponent(i);
                cbField.setSelectedItem(rowMap.get(cbField.getName()));
            }
            
        }
        /*  If declared individually, code will look like this:
        *
        * 
        * cbAccount.setSelectedItem(rowMap.get(cbAccount.getName()));
        * 
        * 
        */
    }
    
    private void clearAllFields(javax.swing.JPanel thisPanel) {

        for (int intIndex = 0; intIndex < thisPanel.getComponentCount(); intIndex++) {
            if(thisPanel.getComponent(intIndex) instanceof javax.swing.JPanel){
                clearAllFields((javax.swing.JPanel)thisPanel.getComponent(intIndex));
            } else if (thisPanel.getComponent(intIndex) instanceof javax.swing.JTextField) {
                javax.swing.JTextField txtField = (javax.swing.JTextField) thisPanel.getComponent(intIndex);
                txtField.setText("");
            } else if (thisPanel.getComponent(intIndex) instanceof javax.swing.JComboBox) {
                javax.swing.JComboBox cbField = (javax.swing.JComboBox) thisPanel.getComponent(intIndex);
                
                if (cbField.getItemCount() == 0) {
                } else {
                    cbField.setSelectedIndex(0);
                }
            }
        }
        /*
         * Reload Default Values
         */
        txtQty.setText("1.00");
        txtUnitCost.setText("0.00");
        txtTaxable.setText("0.00");
        txtVAT.setText("0.00");
        txtWTax.setText("0.00");
        txtTranAmt.setText("0.00");
    } 
    
    
    private void enableAllFields(boolean blnOption){
        
        for (int intIndex = 0; intIndex < dtlPanel.getComponentCount(); intIndex++) {
            
            if(dtlPanel.getComponent(intIndex) instanceof javax.swing.JPanel){
                javax.swing.JPanel thisPanel = (javax.swing.JPanel)dtlPanel.getComponent(intIndex);
                
                for (int intIndex2 = 0; intIndex2 < thisPanel.getComponentCount(); intIndex2++) {
            
                    if (thisPanel.getComponent(intIndex2) instanceof javax.swing.JTextField) {
                        javax.swing.JTextField txtField = (javax.swing.JTextField) thisPanel.getComponent(intIndex2);
                        txtField.setEnabled(blnOption);
                    } else if (thisPanel.getComponent(intIndex2) instanceof javax.swing.JComboBox) {
                        javax.swing.JComboBox cbField = (javax.swing.JComboBox) thisPanel.getComponent(intIndex2);
                        cbField.setEnabled(blnOption);
                    } else if (thisPanel.getComponent(intIndex2) instanceof net.sourceforge.jcalendarbutton.JCalendarButton) {
                        net.sourceforge.jcalendarbutton.JCalendarButton calField = (net.sourceforge.jcalendarbutton.JCalendarButton) thisPanel.getComponent(intIndex2);
                        calField.setEnabled(blnOption);
                    } 
                }
                
            } else if (dtlPanel.getComponent(intIndex) instanceof javax.swing.JTextField) {
                javax.swing.JTextField txtField = (javax.swing.JTextField) dtlPanel.getComponent(intIndex);
                txtField.setEnabled(blnOption);
            } else if (dtlPanel.getComponent(intIndex) instanceof javax.swing.JComboBox) {
                javax.swing.JComboBox cbField = (javax.swing.JComboBox) dtlPanel.getComponent(intIndex);
                cbField.setEnabled(blnOption);
            } else if (dtlPanel.getComponent(intIndex) instanceof net.sourceforge.jcalendarbutton.JCalendarButton) {
                net.sourceforge.jcalendarbutton.JCalendarButton calField = (net.sourceforge.jcalendarbutton.JCalendarButton) dtlPanel.getComponent(intIndex);
                calField.setEnabled(blnOption);
            } 
        }
        
        cmdAccount.setEnabled(blnOption);
        cmdSubaccount.setEnabled(blnOption);
        cmdTaxID.setEnabled(blnOption);
        cmdBudgetID.setEnabled(blnOption);
        cmdJONo.setEnabled(blnOption);
        cmdLCID.setEnabled(blnOption);
        cmdProjID.setEnabled(blnOption);
        cmdSubLedger.setEnabled(blnOption);
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnClose;
    private javax.swing.JButton btnNew;
    private javax.swing.JButton btnSave;
    private javax.swing.JComboBox cbAccount;
    private javax.swing.JComboBox cbBudgetID;
    private javax.swing.JComboBox cbJONo;
    private javax.swing.JComboBox cbLCID;
    private javax.swing.JComboBox cbProjID;
    private javax.swing.JComboBox cbSubAccount;
    private javax.swing.JComboBox cbSubLedger;
    private javax.swing.JComboBox cbTaxID;
    private javax.swing.JButton cmdAccount;
    private javax.swing.JButton cmdBudgetID;
    private javax.swing.JButton cmdJONo;
    private javax.swing.JButton cmdLCID;
    private javax.swing.JButton cmdProjID;
    private javax.swing.JButton cmdSubLedger;
    private javax.swing.JButton cmdSubaccount;
    private javax.swing.JButton cmdTaxID;
    private javax.swing.JPanel dtlPanel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel lblAccount;
    private javax.swing.JLabel lblBudgetID;
    private javax.swing.JLabel lblJONo;
    private javax.swing.JLabel lblLCID;
    private javax.swing.JLabel lblParticulars;
    private javax.swing.JLabel lblPostRef;
    private javax.swing.JLabel lblProjID;
    private javax.swing.JLabel lblQty;
    private javax.swing.JLabel lblSubAccount;
    private javax.swing.JLabel lblSubLedger;
    private javax.swing.JLabel lblTaxID;
    private javax.swing.JLabel lblTaxable;
    private javax.swing.JLabel lblTranAmt;
    private javax.swing.JLabel lblUnitCost;
    private javax.swing.JLabel lblVAT;
    private javax.swing.JLabel lblWTax;
    private javax.swing.JPanel panelGroupSegments;
    private javax.swing.JPanel pnlDetail;
    private javax.swing.JPanel pnlInfo;
    private javax.swing.JTextField txtAccount;
    private javax.swing.JTextField txtInterCo;
    private javax.swing.JTextField txtParticulars;
    private javax.swing.JTextField txtPostRef;
    private javax.swing.JFormattedTextField txtQty;
    private javax.swing.JTextField txtSubAccount;
    private javax.swing.JFormattedTextField txtTaxable;
    private javax.swing.JFormattedTextField txtTranAmt;
    private javax.swing.JFormattedTextField txtUnitCost;
    private javax.swing.JFormattedTextField txtVAT;
    private javax.swing.JFormattedTextField txtWTax;
    // End of variables declaration//GEN-END:variables
}
